package com.sjzsqjy.asdtiang.action;

import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sjzsqjy.asdtiang.db.SiteInterface;
import com.sjzsqjy.asdtiang.mysql.Info;

public class IndexAction extends ActionSupport {
	private int isLogin = 1;
	private SiteInterface siteService;
	private List listNews;
	private List listMenus;
	private Info noticeScroll;
	private List listInstrumentScorlls;
	private List listLinks;
	private List listServices;
	private List listFeedBacks;

	public List getListFeedBacks() {
		return listFeedBacks;
	}

	public void setListFeedBacks(List listFeedBacks) {
		this.listFeedBacks = listFeedBacks;
	}

	private Info aboutUs;

	public List getListInstrumentScorlls() {
		return listInstrumentScorlls;
	}

	public void setListInstrumentScorlls(List listInstrumentScorlls) {
		this.listInstrumentScorlls = listInstrumentScorlls;
	}

	public List getListLinks() {
		return listLinks;
	}

	public void setListLinks(List listLinks) {
		this.listLinks = listLinks;
	}

	public List getListServices() {
		return listServices;
	}

	public void setListServices(List listServices) {
		this.listServices = listServices;
	}

	public List getListNews() {
		return listNews;
	}

	public void setListNews(List listNews) {
		this.listNews = listNews;
	}

	public SiteInterface getSiteService() {
		return siteService;
	}

	public void setSiteService(SiteInterface siteService) {
		this.siteService = siteService;
	}

	public int getIsLogin() {
		return isLogin;
	}

	public void setIsLogin(int isLogin) {
		this.isLogin = isLogin;
	}

	public String execute() throws Exception {

		listNews = siteService.getNews();

		
		this.aboutUs = siteService.getAboutUs();
		this.listServices = siteService.getServices();
		this.listFeedBacks = siteService.getFeedBacks();
		Info info;
		for (int i = 0; i < this.listServices.size(); i++) {
			info = (Info) this.listServices.get(i);
			if (info.getTitle().length() > 10) {
				((Info) listServices.get(i)).setTitle(info.getTitle()
						.substring(0, 10));
			}
		}
		
		
		return SUCCESS;
	}

	public String getMenuExecute() throws Exception {
		listMenus = siteService.getMenus();
		return SUCCESS;
	}

	public String getLoginExecute() throws Exception {
		if (ActionContext.getContext().getSession().get("user") != null) {
			return "logined";
		}
		return "login";
	}

	public String getNoticeScrollExecute() throws Exception {

		this.noticeScroll = siteService.getNoticeScorlls();
		this.noticeScroll.setContent(this.noticeScroll.getContent().substring(
				this.noticeScroll.getContent().indexOf(">") + 1,
				this.noticeScroll.getContent().lastIndexOf("<")));
		return "success";
	}
	public String getLinksExecute() throws Exception {
		this.listLinks = siteService.getLinks();
		System.out.println("link size:"+listLinks.size());
		return "success";
	}

	public String getInstrumentScorllsExecute() throws Exception {

		this.listInstrumentScorlls = siteService.getInstrumentScorlls();
		Info info;
		for (int i = 0; i < this.listInstrumentScorlls.size(); i++) {
			info = (Info) this.listInstrumentScorlls.get(i);
			if (info.getTitle().length() > 5) {
				((Info) listInstrumentScorlls.get(i)).setTitle(info.getTitle()
						.substring(0, 5));
			}
		}
		return "success";
	}

	public Info getNoticeScroll() {
		return noticeScroll;
	}

	public void setNoticeScroll(Info noticeScroll) {
		this.noticeScroll = noticeScroll;
	}

	public Info getAboutUs() {
		return aboutUs;
	}

	public void setAboutUs(Info aboutUs) {
		this.aboutUs = aboutUs;
	}

	public List getListMenus() {
		return listMenus;
	}

	public void setListMenus(List listMenus) {
		this.listMenus = listMenus;
	}

}
